package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;

import model.HostAddress;
import model.IPAddress;
import model.Subnet;
import view.components.IpAddressTable;
import view.components.NetworkTree;
import controller.Controller;

public class TreeTablePanel extends JPanel{
	private IpAddressTable table;
	private final NetworkTree tree;
	private static final long serialVersionUID = 1L;

	public TreeTablePanel(){
	this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

	HostAddress host1 = new HostAddress(new IPAddress("192.111.111.0"), "Wayne");
		Subnet subnet1 = new Subnet(host1.getHostAddress(), 10, "");
		Subnet subnet2 = new Subnet(host1.getHostAddress(), 10, "");
	ArrayList<Subnet> listeSubnet1 = new ArrayList<Subnet>();
	listeSubnet1.add(subnet1);
	listeSubnet1.add(subnet2);
	host1.setSubnet(listeSubnet1);
	
	HostAddress host2 = new HostAddress(new IPAddress("192.222.222.0"), "Chuck");
		Subnet subnet3 = new Subnet(host2.getHostAddress(), 10, "");
		Subnet subnet4 = new Subnet(host2.getHostAddress(), 10, "");
	ArrayList<Subnet> listeSubnet2 = new ArrayList<Subnet>();
	listeSubnet2.add(subnet3);
	listeSubnet2.add(subnet4);
	host2.setSubnet(listeSubnet2);
	
	ArrayList<HostAddress> liste = new ArrayList<HostAddress>();
	liste.add(host1);
	liste.add(host2);
	Controller con = Controller.getInstance();
		con.setHosts(liste);
	
	tree = new NetworkTree();
		JButton addButton = new JButton("Hinzufügen");
	addButton.addActionListener(new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent arg0) {
				tree.addRow("Test", "");
			
		}
	});
	this.add(tree);
		this.add(new IpAddressTable());
	this.add(addButton);
		setName("Übersicht");
	}

	public IpAddressTable getTable() {
		return table;
	}

}
